//
// Created by Bili_TianX_Computer on 2021/7/8.
//

#ifndef SUPERMARKETMANAGESYSTEM_PRODUCTPANEL_H
#define SUPERMARKETMANAGESYSTEM_PRODUCTPANEL_H

#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QTableWidget>
#include <QCheckBox>
#include <QPushButton>
#include <QInputDialog>
#include <QLineEdit>
#include <QDebug>
#include <QDialog>
#include <QMessageBox>
#include <QDialogButtonBox>

#include "../../data/ProductDataManager.h"
#include "../../data/UserDataManager.h"
#include "AddProductDialog.h"
#include "../user/AdminUserManageDialog.h"

class ProductPanel : public QWidget
{
Q_OBJECT
public:
    int selectedRow = -1;

    QPushButton *addButton;
    QPushButton *queryButton;
    QPushButton *sortButton;
    QPushButton *adminButton;
    QPushButton *removeButton;
    QTableWidget *productTable;

    QHBoxLayout *buttonLayout;
    QVBoxLayout *widgetLayout;


    ProductPanel();

    void addProductToTable(Product product);

    void modifyProductFromTable(Product product, int r);

    Product getProductFromTable(int row) const;

    void closeEvent(QCloseEvent *event) override;

public slots:

    void loginSlot(bool isAdmin);

    void addButtonClickedSlot();

    void removeButtonClickedSlot();

    void queryButtonClickedSlot();

    void sortButtonClickedSlot();

    void adminButtonClickedSlot();

    void productTableDoubleClickedSlot(int row, int column);

    void tableSelectRowSlot();
};


#endif //SUPERMARKETMANAGESYSTEM_PRODUCTPANEL_H
